package com.jandan.persistence.sqlmapdao;

import java.sql.SQLException;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.jandan.persistence.iface.WordCommentDao;
import com.jandan.ui.model.WordComment;


/**
 * WordCommentDao接口实现类，使用Ibatis框架进行持久化
 * @author Gong Yong
 * @version 1.0
 * @see com.jandan.persistence.iface.WordCommentDao
 */
public class WordCommentSqlMapDao extends SqlMapClientDaoSupport implements WordCommentDao {
	
	public WordComment getWordCommentByWordCommentID(long wordCommentID) {
		// TODO Auto-generated method stub
		return (WordComment)this.getSqlMapClientTemplate().queryForObject("WordComment.getWordCommentByWordCommentID",wordCommentID);
	}

	
	public List<WordComment> getWordCommentListByWordID(long wordID) {
		// TODO Auto-generated method stub
		return this.getSqlMapClientTemplate().queryForList("WordComment.getWordCommentListByWordID", Long.valueOf(wordID));
	}

	
	public long insertWordComment(WordComment wordComment) {
		// TODO Auto-generated method stub
		long wordCommentID = 0;
		try {
			this.getSqlMapClient().startTransaction();
			this.getSqlMapClientTemplate().insert("WordComment.insertWordComment",wordComment);
			wordCommentID = (Long)getSqlMapClientTemplate().queryForObject("WordComment.lastInsertWordCommentID");
			this.getSqlMapClient().commitTransaction();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				this.getSqlMapClient().endTransaction();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return wordCommentID;
	}

	
	public void updateWordComment(WordComment wordComment) {
		// TODO Auto-generated method stub
		this.getSqlMapClientTemplate().update("WordComment.updateWordComment",wordComment);
	}
	
	
	public void deleteWordComment(long wordCommentID) {
		// TODO Auto-generated method stub
		this.getSqlMapClientTemplate().delete("WordComment.deleteWordComment", Long.valueOf(wordCommentID));
	}


	public int getWordCommentCountByWordID(long wordID) {
		// TODO Auto-generated method stub
		return (Integer)this.getSqlMapClientTemplate().queryForObject("WordComment.getWordCommentCountByWordID",wordID);
	}
}
